/* QUICK CHAT DEMO */
require('/ddview');
$.job = function(key) {
  var msgbox = new $.ddview(key, 'job')

  msgbox.checkElement = function(msg) {
    return msg && msg.message && msg.message.length > 0;
  };

  parentAfterAddElement = msgbox.afterAddElement
  msgbox.afterAddElement = function (element) {
    console.log('afterAddElement personal')    
    parentAfterAddElement(element)
  }

  parentAfterCreateView = msgbox.afterCreateView
  msgbox.afterCreateView = function (view) {
    console.log('afterCreateView personal')    
    parentAfterCreateView()
  }

  msgbox.beforeDropElement = function(element) {
    console.log('beforDropElement personal')
    return true
  }

  msgbox.afterDropElement = function(element) {
    console.log('afterDropElement personal')
    $( this ).addClass( "ui-state-highlight" )
  }

  msgbox.on('submit', function() {

    // Grab the message from the text box
    var msg = {
      message: msgbox.find('input').first().val()
    }
    
    // Call the 'send' funtion (below) to ensure it's valid before sending to the server
    return msgbox.addElement(msg, function(success) {
      if (success) {
        return msgbox.find('input').first().val('');
      } else {
        return alert('Oops! Unable to send message');
      }
    });
  });

  return msgbox
}

// Private functions
